<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="账号：" prop="account">
    <el-input v-model="ruleForm.account"></el-input>
  </el-form-item>
  <el-form-item label="密码：" prop="password">
    <el-input v-model="ruleForm.password" type="password"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
  </el-form-item>
</el-form>
  </div>
</template>

<script>
import md5 from "md5";
  export default {
    data() {
      return {
        ruleForm: {
            account: "admin",
            password:"123456"
        },
        rules: {
            account: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
          ],
          password:[
          { required: true, message: '请输入密码', trigger: 'blur' },
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // alert('submit!');//*********ajax***************
            this.loginFun()//ajax
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    //   resetForm(formName) {
    //     this.$refs[formName].resetFields();
    //   },
     async loginFun(){
           let result=await this.$http.post("/adminUser/login",{
               userName: this.ruleForm.account,
               passwordMd5: md5(this.ruleForm.password)
                })
           if(result.resultCode==200){//跳转
            sessionStorage.setItem("token",result.data);//token登录成功 存token


            this.$router.push("/index")

           }
      }
    }
  }
</script>

<style>

</style>